In [1]:
import numpy as np
import pandas as pd
import math
import cmath
from scipy.optimize import root
import matplotlib.pyplot as plt
%matplotlib inline

In [2]:
archivo_de_datos = ("Table1.txt")
archivo_de_datos


Out[2]:
'Table1.txt'

In [ ]:


In [3]:
c1 = np.linspace(1157 - 112, 1157 + 112, 10)
c1


Out[3]:
array([ 1045.        ,  1069.88888889,  1094.77777778,  1119.66666667,
        1144.55555556,  1169.44444444,  1194.33333333,  1219.22222222,
        1244.11111111,  1269.        ])

ejemplo de InterfazPolimero2


In [10]:
class InterfazPolimero2:
    def __init__ (self, archivo_de_datos, c1):
        self.archivo_de_datos = archivo_de_datos
        self.c1 = c1
        
    def leerDatos(self):
        self.datos = pd.read_csv(self.a,sep=" ")
        self.valoresDatos = self.datos.values
        return self.datos
    
    def asignarParametros(self):
        self.Experiment = self.valoresDatos[:,0]
        self.Thickness = self.valoresDatos[:,1]
        self.FoodSimulant = self.valoresDatos[:,2]
        self.Cpo = self.valoresDatos[:,3]
        self.K = self.valoresDatos[:,4]
        self.Dp = self.valoresDatos[:,5]
        self.RMSE = self.valoresDatos[:,6]
        self.k = self.valoresDatos[:,7]
        self.c4 = self.valoresDatos[:,8]
        
    def inicializarC2(self):
        self.c2 = np.zeros(10)
        self.dimension = np.shape(self.c2)
        print(self.dimension)
        return self.c2
    
    def calcul(self):
        self.j1 = (self.Dp / (self.Thickness / 2)) * ( self.c1 - self.c2)
        self.c3 = self.c2 / self.K
        self.j2 = self.k * (self.c3 - self.c4)
        return (self.j1 - self.j2) / self.j1

In [ ]:


In [11]:
class InterfazPolimero:
    def __init__ (self,a):
        self.a=a
        self.c1 = np.linspace(1157-112,1157+112,10)
    def lire(self):
        tab = pd.read_csv(self.a,sep=" ")
        coef =tab.values
        self.Experiment = coef[:,0]
        self.Thickness = coef[:,1]
        self.FoodSimulant = coef[:,2]
        self.Cpo = coef[:,3]
        self.K = coef [:,4]
        self.Dp = coef[:,5]
        self.RMSE = coef[:,6]
        self.k = coef[:,7]
        self.c4 = coef[:,8]
        return tab
#         self.c1 = np.linspace(1157-112,1157+112,10)
        self.D = self.Dp
        self.L = self.Thickness
        self.K1 = self.K 
#         self.c4 = 0.05
#         self.k = 7.14e-6
        self.c2 = np.zeros(10)
        dimension = np.shape(self.c2)
    try: 
        calcul(self,c2,D,k,K,c4,c1,L)
    except:
        def calcul(self,c2,D,k,K,c4,c1,L): 
            self.j1 = ((float(self.Dp)/(float(self.Thickness)/2))*(float(self.c1)-float(self.c2)))
            self.c3 = float(self.c2)/float(self.K)
            self.j2 = float(self.k)*(float(self.c3)-float(self.c4))
            return (j1-j2)/j1
        def calcul2(self):
            i = 0
            for self.c1i in self.c1: 
                for self.Dpi in self.Dp:
                    for self.ki in self.k:
                        for self.Ki in self.K:
                            for self.Thicknessi in self.Thickness:
                                sol = root(calcul,15,args=(float(self.Dp),float(self.k),float(self.K),float(self.c4),float(self.c1),float(self.Thickness)))
                                c2[i]= sol.x 
                                i = i+ 1
            return c2

In [12]:
p = InterfazPolimero("Table1.txt")
p


Out[12]:
<__main__.InterfazPolimero at 0x7f4b704f61d0>

In [14]:
p.lire()


Out[14]:
Experiment Thickness FoodSimulant Cpo K Dp RMSE k c4
0 1 146 EtOH95% 1157(+/-112) 52.0 1.950000e-13 1.5 0.000007 0.05
1 2 146 NaN 2440(+/-62) 35.0 1.970000e-13 3.0 0.000007 0.05
2 3 146 NaN 3152(+/-40) 24.0 2.000000e-13 2.6 0.000007 0.05
3 4 146 NaN 5950(+/-35) 0.5 2.000000e-13 2.3 0.000007 0.05
4 5 50 EtOH95% 2050(+/-110) 334.0 1.000000e-14 3.1 0.000007 0.05
5 6 146 NaN 2440(+/-62) 35.0 1.970000e-13 3.0 0.000007 0.05
6 7 190 NaN 2878(+/-115) 34.0 2.000000e-13 4.6 0.000007 0.05
7 8 50 EtOH10% 2050(+/-110) 0.0 0.000000e+00 0.0 0.000007 0.05
8 9 146 NaN 2440(+/-62) 0.0 0.000000e+00 0.0 0.000007 0.05
9 10 190 NaN 2878(+/-115) 0.0 0.000000e+00 0.0 0.000007 0.05

In [15]:
p.calcul2()


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-c03304d02e40> in <module>()
----> 1 p.calcul2()

<ipython-input-11-07657f1a171d> in calcul2(self)
     39                         for self.Ki in self.K:
     40                             for self.Thicknessi in self.Thickness:
---> 41                                 sol = root(calcul,15,args=(float(self.Dp),float(self.k),float(self.K),float(self.c4),float(self.c1),float(self.Thickness)))
     42                                 c2[i]= sol.x
     43                                 i = i+ 1

TypeError: only length-1 arrays can be converted to Python scalars

In [16]:
c1 = np.linspace(1157-112,1157+112,10)
K = 0.1
c4 = 0.05
k = 7.14e-6
D = 1.93e-13
L = 1
c2 = np.zeros(10)
dimension = np.shape(c2)
def calcul(c2,D,k,K,c4,c1,L): 
    j1 = (D/(L/2)*(c1-c2))
    c3 = c2/K
    j2 = k*(c3-c4) 
    return (j1-j2)/j1
def calcul2():
    i = 0
    for c1i in c1: 
        sol = root(calcul,15,args=(D,k,K,c4,c1,L))
        c2[i]= sol.x 
        i = i + 1 
    return c2

In [17]:
calcul2()


Out[17]:
array([ 0.00500565,  0.00500565,  0.00500565,  0.00500565,  0.00500565,
        0.00500565,  0.00500565,  0.00500565,  0.00500565,  0.00500565])

In [18]:
a =np.linspace(1,11,10)
a


Out[18]:
array([  1.        ,   2.11111111,   3.22222222,   4.33333333,
         5.44444444,   6.55555556,   7.66666667,   8.77777778,
         9.88888889,  11.        ])

In [19]:
b = np.zeros(10)
for ai in a:
    b = ai + 1

In [20]:
b


Out[20]:
12.0

In [21]:
class InterfazPolimero:
    def __init__ (self,a):
        self.a=a
        self.c1 = np.linspace(1157-112,1157+112,10)
    def lire(self):
        tab = pd.read_csv(self.a,sep=" ")
        coef =tab.values
        self.Experiment = coef[:,0]
        self.Thickness = coef[:,1]
        self.FoodSimulant = coef[:,2]
        self.Cpo = coef[:,3]
        self.K = coef [:,4]
        self.Dp = coef[:,5]
        self.RMSE = coef[:,6]
        self.k = coef[:,7]
        self.c4 = coef[:,8]
        return tab

In [22]:
p.lire()


Out[22]:
Experiment Thickness FoodSimulant Cpo K Dp RMSE k c4
0 1 146 EtOH95% 1157(+/-112) 52.0 1.950000e-13 1.5 0.000007 0.05
1 2 146 NaN 2440(+/-62) 35.0 1.970000e-13 3.0 0.000007 0.05
2 3 146 NaN 3152(+/-40) 24.0 2.000000e-13 2.6 0.000007 0.05
3 4 146 NaN 5950(+/-35) 0.5 2.000000e-13 2.3 0.000007 0.05
4 5 50 EtOH95% 2050(+/-110) 334.0 1.000000e-14 3.1 0.000007 0.05
5 6 146 NaN 2440(+/-62) 35.0 1.970000e-13 3.0 0.000007 0.05
6 7 190 NaN 2878(+/-115) 34.0 2.000000e-13 4.6 0.000007 0.05
7 8 50 EtOH10% 2050(+/-110) 0.0 0.000000e+00 0.0 0.000007 0.05
8 9 146 NaN 2440(+/-62) 0.0 0.000000e+00 0.0 0.000007 0.05
9 10 190 NaN 2878(+/-115) 0.0 0.000000e+00 0.0 0.000007 0.05

In [ ]: